yRadio
Description
The yRadio is a clickable element with different optical styles, used to indicate its different states. The yRadio can be used to toggle a state or mirror a user selection where only one selection is possable. For example:
Basic Structure
In the following the basic structure of the yRadio shall be explained. For the general structure of a yComponent please visit the YBase-components basic-structure.
The yRadio as seen above contains a label and the radio.
Label
The label contains the text inside the button. It is on the right side of the component. By changing the inner padding of the button, the label gets moved too. You can find further explanation at the Label Property.
Radio
A radio button, often referred to as a radio bubble, is a graphical user interface element that allows the user to choose only one option from a set of predefined options. It appears as a small circle that, when selected, is filled or marked with a dot or check inside. Radio buttons are typically grouped together to form a radio group, ensuring that selecting one button will deselect any other previously selected button within the same group. This makes them ideal for presenting exclusive choices where only one selection is allowed, such as choosing a shipping option, selecting a gender, or picking a payment method.
Properties
Through its various properties the yRadio can be configured to suit your needs. The display below provides you with an overview of all the yRadio properties.
Properties can be changed directly through three methods:
- Inside the Toolbar, which is positioned in your workarea next to your component where you need it. It shows the most important properties, thus providing a fast and efficient way to configure your component in the most basic way.
- It may also occur in the Toolbar Extension, which is a seamless extension accesible as a dropdown item of the Toolbar. It extends the functionality of the Toolbar by providing advanced pickers for most used properties.
- Inside the Detail Panel, which is located in the righthand drawer. Every property of a component can be configured here.
- Generic
- Style
- Radio
- Links
- Events
METAread more
The identifier of the component that is unique within a page.
The type of the component. For this component it is -radio.
The custom name of the component. It serves for better identification of the component.
The custom version of the Radio-component. This can be used to ensure that all components work well together.
The CoreTheme, which will be apllied to the Radio. For further information on themes visit the themes page.
The subtheme subordinated to the previously specified CoreTheme, which will be apllied to the Radio. For further information on themes visit the themes page.
The group theme is a further variation of the subtheme which is specified especially for variations of a component inside the subtheme. For further information on themes visit the Theme-Manager page.
DISPLAYread more
This property specifies the display behavior of the component. This can be be set to:
- none
- block
- flex
- inline
This property specifies the type of positioning method used for the component. This can be be set to:
- static
- relative
- absolute
- sticky
- fixed
This property can toggle the visibility of the component. The two modes are completely hidden and fully shown.
SIZEread more
The minimum value for the width of the component. This can be set in:
- px
- pt
- em
- vw
- vh
- %
The minimum value for the height of the component. This can be set in:
- px
- pt
- em
- vw
- vh
- %
The value for the width of the component. This can be set in:
- px
- pt
- em
- vw
- vh
- %
- auto
The value for the height of the component. This can be set in:
- px
- pt
- em
- vw
- vh
- %
- auto
The maximum value for the width of the component. This can be set in:
- px
- pt
- em
- vw
- vh
- %
- none
The maximum value for the height of the component. This can be set in:
- px
- pt
- em
- vw
- vh
- %
- none
The flex property sets the length on flexible items. This sets the value in n-fold shares extrapolated to all other components with the flex display within the same container.
PLACEMENTread more
This property creates a space around the component, outside of the top border. This can be set in percent or pixels.
This property creates a space around the component, outside of the right border. This can be set in percent or pixels.
This property creates a space around the component, outside of the bottom border. This can be set in percent or pixels.
This property creates a space around the component, outside of the left border. This can be set in percent or pixels.
This property creates a space within the component, inside of the top border. This can be set in percent or pixels.
This property creates a space within the component, inside of the right border. This can be set in percent or pixels.
This property creates a space within the component, inside of the bottom border. This can be set in percent or pixels.
This property creates a space within the component, inside of the top border. This can be set in percent or pixels.
BACKGROUNDread more
The color of the background. This can be set as a color from a palette or a custom hex color.
BORDERread more
The color of the top border. This can be set as a color from a palette or a custom hex color.
The style of the top border. This can be be set to:
- solid
- dotted
- dashed
- none
The width of the top border. This can be set in percent or pixels.
The color of the right border. This can be set as a color from a palette or a custom hex color.
The style of the right border. This can be be set to:
- solid
- dotted
- dashed
- none
The width of the right border. This can be set in percent or pixels.
The color of the bottom border. This can be set as a color from a palette or a custom hex color.
The style of the bottom border. This can be be set to:
- solid
- dotted
- dashed
- none
The width of the bottom border. This can be set in percent or pixels.
The color of the left border. This can be set as a color from a palette or a custom hex color.
The style of the left border. This can be be set to:
- solid
- dotted
- dashed
- none
The width of the left border. This can be set in percent or pixels.
The radius of the corners of all the borders. This can be set in percent or pixels.
SHADOWread more
The shadow of the component. This is set by the 4 sub-properties x, y, blur and spread of the shadow-property, which can be further read about in the shadow-property section.
OPACITYread more
The opacity of all colored parts of the component. This value is set in percent.
LABELread more
The color of the label text. This can be set as a color from a palette or a custom hex color.
The font-family of the label text. This can be picked from a large list of provided fonts.
The font-weight of the label text. This can be set in a custom number, as example:
- 400 = normal(regular)
- 500 = medium
- 600 = semi bold
- 700 = bold
The font-style of the label text. This can be set to normal, italic or oblique.
The text-transformation of the label text. This can be set to:
- capitalize
- uppercase
- lowercase
- none
- full-width
The text-decoration of the label text. This can be set to:
- strikethrough
- underline
The font-size of the label text. This can be set in: -cm
- mm
- in
- px
- em
- ex
- ch
- rem
The actual written text in the label. There is no limit to the number of characters.
The actual written text in the left label. There is no limit to the number of characters.
RADIOread more
The color of the turned off radio background. This can be set as a color from a palette or a custom hex color.
The color of the border of the turned off radio. This can be set as a color from a palette or a custom hex color.
The color of the turned on radio background. This can be set as a color from a palette or a custom hex color.
The color of the icon inside the turned on radio. This can be set as a color from a palette or a custom hex color.
The color of the border of the turned on radio. This can be set as a color from a palette or a custom hex color.
The color of the circle-animation of the radio. This can be set as a color from a palette or a custom hex color.
The opacity of the colored circle animation of the radio. This value is set in percent.
The value for the width of the border of the radio. This can be set in:
- px
- pt
- em
- vw
- vh
- %
- auto
The style of the radio of the selected row. This can be be set to:
- solid
- dotted
- dashed
- none
The size of the circle animation of the radio. This value is set in px.
The preset value of the radio (e.g. 'true' or 'false').
The value that will be used as a means of comparision to check if the current radio button is active.
STATEread more
This property can disable or enable the disabled-state of the Radio-component.
This property can disable or enable the error-state of the Radio-component.
TOOLTIPread more
The text of the tooltip, which is displayed when hovering over the Radio-component. If you do not insert anything, no tooltip appears.
ERRORread more
The message to be displayed, if an error occurs.
MISCread more
This property specifies if a deselection, by clicking again, is possible.
VALUEread more
This property defines a link to another component by specifying the componentId or componentName, Page, Component, ID, Event. The data from the link will represent a comparison value.
Usage
In this section you'll find a collection of application scenarios and examples that illustrate how to leverage the yRadio in ways that deviate from its standard behavior, as defined by yBase. This section aims to inspire and guide you through various possibilities, helping you to implement more complex or unique functionalities tailored to your specific needs. General properties that are universally applicable can be found in the yBase usage section.
Variations
- Elevated
- Flat
- Outlined
- Rounded
- Plain
Radio Stylings
- Minimalist
- Bold
- Luminous
Label Variations
- Label Left
- Label Right
- Label Both
Dynamic Value Assignment
The yRadio component is designed to facilitate dynamic user interactions within your application. It achieves this through two primary properties found within the "style" > "radio" category, value and comparisonVal.
Value Property
The value property is intended to be set externally, either by user action or programmatically via JavaScript. This property represents the current state or selection of the yRadio component.
Via Javascript:
// function onButton_1_EvtClicked (apiObject, component, eventData)
const shipingMethod = "LKW";
const radioComponent = apiObject.ui.getObject(1, "y-radio");
radioComponent.set("style", "radio", "value", shipingMethod);
//}
In this snippet, yourDesiredValue is the actual value that you want the yRadio to hold, which will reflect the user's selection. Alternatively, yRadio can obtain its value through a SourceLink. This method establishes a connection between yRadio and another component. The value received through the SourceLink is then compared against the comparisonVal to determine the radio button's state. The value can be coupled to a Clipboard value via the SourceLink Picker.
Via SourceLink:
- Create a yRadio component in your application.
- Create a yInput component in your application.
- Select the created yRadio and open the Detail Panel.
- Within these settings, proceed to the "Links" section and open "Value".
- Create a new sourceLink -> select the yInput you just created and choose input-string as an event.
In this example you should find a way to demand either by mask/validation or javascript to make sure the input-string is represented as a radio-value.
ComparisonVal Property
The comparisonVal serves as a unique identifier for a yRadio component within a group of similar radio buttons. To create a set of mutually exclusive selections — where choosing one option deselects the others — multiple yRadio components can share the same comparisonVal.
For instance, if you have a group of radio buttons for selecting a shipping method, each radio button's comparisonVal might be set to "shippingMethod". The one whose value matches the comparisonVal will be marked as selected:
// function onButton_1_EvtClicked (apiObject, component, eventData)
const shipingMethod = "SHIP";
const radioComponent = apiObject.ui.getObject(1, "y-radio");
radioComponent.set("style", "radio", "comparisonVal", shipingMethod);
//}
The Comparisonval should only seldomly be changed via javascript.
Coupling and Selection State
When you have multiple radio buttons with the same comparisonVal, they are effectively coupled. The selection state (true or false) of these yRadio components is determined by comparing their value with their comparisonVal. When the value matches the comparisonVal, that particular radio button is selected (its state is true). If they don't match, the radio button remains unselected (its state is false).
This mechanism ensures that within a set of yRadio components with the same purpose, only the one with a matching value will be selected, enforcing the rule that only one option can be chosen at a time in a radio group.
By leveraging the value and comparisonVal properties, yRadio components can be effectively used to create a responsive and intuitive selection interface within your application.
Real Life Use Cases
Payment for a shop
This example provides the code to get the selected Payment-Method from radio buttons without the usage of a sourceLink for an external radio value. When a button is clicked the selected payment method will be fetched.
// function onButton_1_EvtClicked (apiObject, component, eventData)
// Assume we have 3 radio buttons for payment methods: "Credit Card", "PayPal", "Bank Transfer"
// Each radio button has a unique ID
let selectedMethod;
const paymentMethods = [
{
name: "Credit Card",
radioId: 4,
},
{
name: "PayPal",
radioId: 5,
},
{
name: "Bank Transfer",
radioId: 6,
},
];
paymentMethods.forEach((method) => {
const radioButton = apiObject.ui.getObject(method.radioId, "y-radio");
const selectedValue = radioButton.get("style", "radio", "value");
const comparisonValue = radioButton.get("style", "radio", "comparisonValue");
const isSelected = selectedValue == comparisonValue;
if (isSelected) {
selectedMethod = method.name;
console.log(`Selected payment method: ${method.name}`);
}
});
if (!selectedMethod) {
alert("Please select a payment method.");
return false;
}
return true;
//}
Displaymodes
In this example three radios with the keys depicted in displayModes variables are needed. The following function has to be included in each of those radios as the 'EvtClicked'-Function.
// function onRadio_1_EvtClicked (apiObject, component, eventData)
// Function to toggle UI elements based on the selected display mode using YRadio
const displayModes = {
BasicView: ["basicElement1", "basicElement2"], // List of elements to be shown in Basic View
AdvancedView: ["advancedElement1", "advancedElement2"], // List of elements for Advanced View
ExpertView: ["expertElement1", "expertElement2"], // List of elements for Expert View
};
// Assume the radio buttons have IDs that match the display modes
const selectedMode = component.get("style", "radio", "value");
// Hide all elements first
Object.values(displayModes)
.flat()
.forEach((elementId) => {
const element = apiObject.ui.getObject(elementId);
element.set("generic", "display", "visible", "none");
});
// Show elements for the selected mode
if (displayModes[selectedMode]) {
displayModes[selectedMode].forEach((elementId) => {
const element = apiObject.ui.getObject(elementId);
element.set("generic", "display", "visible", "block");
});
console.log(`Display mode set to: ${selectedMode}`);
} else {
console.error("Selected mode is not recognized:", selectedMode);
}
//}
Special Picker
SourceLink Picker
There is a special picker for the yRadio in the Toolbar as a Toolbar Extension which will be used to link the component to a logic of 2 or more other components. This is a kind of SourceLink Picker, similar to other SourceLink Pickers to be found in other components.